//
// Created by user on 2022/1/18.
//
#include <iostream>
#include <vector>

using namespace std;

void nextPermutation(vector<int>& nums) {
    int n = nums.size();
    if(n<=1){return;}
    int i = n-2;
    while (i>=0 && nums[i]>=nums[i+1]){i--;}

    if(i>=0){
        int j=n-1;
        while (j>i && nums[j]<=nums[i]){j--;}
        swap(nums[i], nums[j]);
    }

    reverse(nums.begin()+i+1, nums.end());
}